<template>
  <div>
    <p>
    <van-field label="章节:" v-model="form.name"/>

      <select name="" id="" v-model="form.courses_id">
        <option :value="i.id" v-for="i in klist">{{i.title}}</option>
      </select>
    </p>
    上传视频 <van-uploader :after-read="vedio_upload" />
    <van-button  @click="add_jie">添加</van-button>

  </div>
</template>

<script>
export default {
  name: "zhangjie",
  data() {
    return {
      form:{vedio_url:''},
      klist: []
    }
  },
  methods:{
    add_jie(){
      this.$axios.post('users/jieM',this.form).then(res=>{
        if(res.data.code==200){
          alert('ok')
        }else {
          alert('no')
        }
      })
    },
    get_cousers(){
      this.$axios.get('users/get_courses').then(res=>{
        this.klist = res.data.list
      })
    },
    vedio_upload(file){
      if(this.form.courses_id){
        let formdata = new FormData()
        formdata.append('file',file.file)
        formdata.append('courses_id',this.form.courses_id)
        this.$axios.post('users/vedioUpload',formdata).then(res=>{
          this.form.vedio_url =res.data.url
        })
      }else {
        alert("请选择课程后再上传视频")
      }

    }
  },mounted() {
    this.get_cousers()
  }
}
</script>

<style scoped>

</style>
